package com.wn.sk.product.core.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.wn.common.api.Result;
import com.wn.sk.product.core.entity.Product;
import com.wn.sk.product.core.vo.SeckillVo;
import com.wn.sk.product.core.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author yellow docker
 * @since 2022-09-02
 */
@Api(tags = "商品服务")
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @ApiOperation("查询所有的产品")
    @GetMapping("all")
    public Result findProduct(){
        List<Product> list = productService.list();
        if (CollectionUtils.isEmpty(list)){
            return Result.error();
        }
        return Result.common(list);
    }

    @ApiOperation("查询秒杀活动商品信息")
    @GetMapping("sk")
    public Result findSkProduct() throws JsonProcessingException {

        List<SeckillVo>  skcKillVos= productService.listSkProduct();
        if (CollectionUtils.isEmpty(skcKillVos)){
            return Result.error();
        }
        return Result.common(skcKillVos);
    }

}

